<?php 
/*
 module:		保单列表
 create_time:	2021-03-03 10:01:34
 author:		
 contact:		
*/

namespace app\admin\controller\Insurance;

use app\admin\service\Insurance\InsurancePolicyService;
use app\admin\model\Insurance\InsurancePolicy as InsurancePolicyModel;
use app\admin\controller\Admin;
use think\facade\Db;

class InsurancePolicy extends Admin {


	/*首页数据列表*/
	function index(){
		if (!$this->request->isAjax()){
			return view('index');
		}else{
			$limit  = $this->request->post('limit', 20, 'intval');
			$offset = $this->request->post('offset', 0, 'intval');
			$page   = floor($offset / $limit) +1 ;

			$where = [];
			$where['insured_name'] = $this->request->param('insured_name', '', 'serach_in');
			$where['insured_type'] = $this->request->param('insured_type', '', 'serach_in');
			$where['insured_card_no'] = $this->request->param('insured_card_no', '', 'serach_in');
			$where['insured_card_type'] = $this->request->param('insured_card_type', '', 'serach_in');

			$order  = $this->request->post('order', '', 'serach_in');	//排序字段 bootstrap-table 传入
			$sort  = $this->request->post('sort', '', 'serach_in');		//排序方式 desc 或 asc

			$field = 'id,insured_name,insured_type,insured_card_no,insured_card_type,insured_card_valid,insured_gender,insured_email,insured_mobile,with_holder_relation,with_holder_relation_dec,card_obverse_url,card_reverse_url,policy_name,ic_short_name,product_id,ic_id,ic_code,product_category,begin_date,is_holder';
			$orderby = ($sort && $order) ? $sort.' '.$order : 'id desc';

			$res = InsurancePolicyService::indexList(formatWhere($where),$field,$orderby,$limit,$page);
			return json($res);
		}
	}

	/*添加*/
	function add(){
		if (!$this->request->isPost()){
			return view('add');
		}else{
			$postField = 'insured_name,insured_type,insured_card_no,insured_card_type,insured_card_valid,insured_gender,insured_email,insured_mobile,userid,with_holder_relation,with_holder_relation_dec,card_obverse_url,card_reverse_url,policy_name,ic_short_name,product_id,ic_id,ic_code,product_category';
			$data = $this->request->only(explode(',',$postField),'post',null);
			$res = InsurancePolicyService::add($data);
			return json(['status'=>'00','msg'=>'添加成功']);
		}
	}



}

